import request from '@/utils/request'
import axios from 'axios'
// 查询附件列表
export function listAttachment(query) {
  return request({
    url: '/system/attachment/list',
    method: 'get',
    params: query
  })
}

// 查询附件详细
export function getAttachment(gid) {
  return request({
    url: '/system/attachment/' + gid,
    method: 'get'
  })
}

// 新增附件
export function addAttachment(data) {
  return request({
    url: '/system/attachment',
    method: 'post',
    data: data
  })
}

// 修改附件
export function updateAttachment(data) {
  return request({
    url: '/system/attachment',
    method: 'put',
    data: data
  })
}

// 删除附件
export function delAttachment(gid) {
  return request({
    url: '/system/attachment/' + gid,
    method: 'delete'
  })
}

// 导出附件
export function exportAttachment(query) {
  return request({
    url: '/system/attachment/export',
    method: 'get',
    params: query
  })
}
  //下载图片文件
  export function downloadAttachment (url,name){
      axios.get(url, {responseType: 'blob'}).then((res) => {
        const downloadUrl = window.URL.createObjectURL(new Blob([res.data]));
        const link = document.createElement('a');
        link.href = downloadUrl;
        link.setAttribute('download', name);
        document.body.appendChild(link);
        link.click();
        link.remove();
      });
  }

